package router

import (
	"chain_bridge_service/internal/api/chain_apply"
	"chain_bridge_service/internal/api/chain_config"
	"chain_bridge_service/internal/api/chain_to_chain"
	"chain_bridge_service/internal/api/chain_token"
	"chain_bridge_service/internal/api/chain_user_config"
	"chain_bridge_service/internal/api/user"
)

func setApiRouter(r *resource) {
	userHandler := user.New(r.logger, r.mongodb)

	r.mux.Static("/static", "./static")
	login := r.mux.Group("/admin")
	{
		login.POST("/login", userHandler.Login())
	}

	chainTokenHandle := chain_token.New(r.logger, r.mongodb)
	chainHandle := chain_to_chain.New(r.logger, r.mongodb)

	chainApplyHandle := chain_apply.New(r.logger, r.mongodb)
	chainUserConfigHandle := chain_user_config.New(r.logger, r.mongodb)
	chainConfigHandle := chain_config.New(r.logger, r.mongodb)

	//, r.interceptors.CheckSignature(r.mongodb.GetDb())
	api := r.mux.Group("/api")
	chaincurd := chain_to_chain.New(r.logger, r.mongodb)
	//api = r.mux.Group("/api", r.interceptors.CheckSignature(r.mongodb.GetDb()))
	api = r.mux.Group("/api")
	{
		api.POST("/createChainApply", chainApplyHandle.Create())
		api.GET("/getChainApplyList", chainApplyHandle.List())

		//根据链配置的id 获取对应的token
		api.GET("/getChainTokenList", chainTokenHandle.List())

		api.GET("/getChainList", chainHandle.ApiList())

		//获取比例
		api.GET("/getRate", chaincurd.GetRate())
	}

	admin := r.mux.Group("/admin")
	admin = r.mux.Group("/admin", r.interceptors.CheckSignature(r.mongodb.GetDb()))
	{

		//chain_user_config
		admin.GET("/getUserConfigList", chainUserConfigHandle.GetListByUserId())
		admin.POST("/creatUserConfig", chainUserConfigHandle.Create())
		admin.DELETE("/userConfig/:id", chainUserConfigHandle.Delete())
		admin.PATCH("/userConfig/:id", chainUserConfigHandle.Update())
		admin.POST("/updateFeeAddress", chainUserConfigHandle.UpdateAddress())

		//chain_config
		admin.GET("/chainConfigs", chainConfigHandle.List())

		//chain_token
		admin.GET("/chainTokens", chainTokenHandle.GetListByConfigId())

		//测试
		admin.POST("/createChain", chaincurd.Create())
		admin.POST("/updateChain", chaincurd.Update())
		admin.POST("/deleteChain", chaincurd.Delete())
		admin.GET("/findChain", chaincurd.List())

		//获取兑换记录
		admin.GET("/getList", chainApplyHandle.GetList())

	}

}
